package com.softer.wxzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.util.StringUtils;
import com.softer.wxzj.entity.AccReverseRecord;
import com.softer.wxzj.entity.base.BaseEntity;
import com.softer.wxzj.mapper.AccReverseRecordMapper;
import com.softer.wxzj.service.AccKeepAccountService;
import com.softer.wxzj.service.AccReverseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class AccReverseRecordServiceImpl implements AccReverseRecordService {
    @Autowired
    private AccReverseRecordMapper accReverseRecordMapper;
    @Autowired
    private AccKeepAccountService accKeepAccountService;

    /**
     * 冲正业务查询
     *
     * @param page
     * @param accReverseRecord
     * @param fuzzy
     * @return
     */
    @Override
    public PageInfo<AccReverseRecord> getList(Page page, AccReverseRecord accReverseRecord, String fuzzy) {
        List<AccReverseRecord> list = new ArrayList<>();
        //看登录人的是谁若是银行判断银行，若是管理员看房屋地区
        BaseEntity baseEntity = accKeepAccountService.addSelect();
        if (StringUtils.isNotBlank(baseEntity.getBankId())) {
            accReverseRecord.setBankCode(baseEntity.getBankId());
        }
        if (StringUtils.isNotBlank(baseEntity.getZoneCode())) {
            accReverseRecord.setZoneCode(baseEntity.getZoneCode());
        }
        if (StringUtils.isNotBlank(baseEntity.getBankId())) {
            accReverseRecord.setBankCode(baseEntity.getBankId());
        }
        if (StringUtils.isNotBlank(baseEntity.getZoneCode())) {
            accReverseRecord.setZoneCode(baseEntity.getZoneCode());
        }
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        if (StringUtils.isBlank(fuzzy)) {
            list = accReverseRecordMapper.getList(accReverseRecord);
        } else {
            list = accReverseRecordMapper.fuzzyResearch(fuzzy,baseEntity.getZoneCode(), accReverseRecord.getBankCode());
        }
        for(AccReverseRecord accReverseRecord1:list){
            switch (accReverseRecord1.getBusiType()){
                case "310":
                    accReverseRecord1.setBusiType("退款业务");
                    break;
                case "311":
                    accReverseRecord1.setBusiType("交存业务");
                    break;
                case "312":
                    accReverseRecord1.setBusiType("支用业务");
                    break;
                    default:
                        accReverseRecord1.setBusiType("结息业务");
                        break;
            }

        }
        PageInfo<AccReverseRecord> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public CommonResult insert(AccReverseRecord accReverseRecord) {
        return null;
    }

    @Override
    public CommonResult update(AccReverseRecord accReverseRecord) {
        return null;
    }

    @Override
    public CommonResult delete(String id) {
        return null;
    }

    @Override
    public PageInfo<AccReverseRecord> getList(Page page, AccReverseRecord accReverseRecord) {
        return null;
    }

    @Override
    public AccReverseRecord getInfo(String id) {
        return null;
    }


}
